
***************************************
**** 	Table 3: PRODUCTIVITY 		****
***************************************

use "$dir/Data/analysis_main.dta", clear

********** TABLE: Productivity ATE at worker-hour level 

	eststo clear
	
	* Baseline prod - linear
	eststo: reghdfe n_productivity cash_postpay cash_announce blhrprod blhrprod_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
	qui estadd local cont1 "Y"
	qui estadd local cont2 "N"
	qui estadd local cont3 "N"	
	qui estadd local fe1 "Y"
	qui estadd local fe2 "N"	
	lincom cash_postpay - cash_announce
	qui estadd scalar coef1 = r(estimate)
	qui estadd scalar se1 = r(se)			
	qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))	

		
	* Baseline prod - quadratic
	eststo: reghdfe n_productivity cash_postpay cash_announce blhrprod blhrprodsq blhrprod_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
	qui estadd local cont1 "Y"
	qui estadd local cont2 "Y"
	qui estadd local cont3 "N"	
	qui estadd local fe1 "Y"
	qui estadd local fe2 "N"
	lincom cash_postpay - cash_announce
	qui estadd scalar coef1 = r(estimate)
	qui estadd scalar se1 = r(se)			
	qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))	
	
	* Double post lasso
	*** Preferred spec is the one below:
	eststo: reghdfe n_productivity cash_postpay cash_announce blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
	qui estadd local cont1 "Y"
	qui estadd local cont2 "Y"
	qui estadd local cont3 "Y"	
	qui estadd local fe1 "Y"
	qui estadd local fe2 "N"	
	lincom cash_postpay - cash_announce
	qui estadd scalar coef1 = r(estimate)
	qui estadd scalar se1 = r(se)			
	qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))	
	
	* Adds hour and day FE
	eststo: reghdfe n_productivity cash_postpay cash_announce blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup day Hour_Start)
	qui estadd local cont1 "Y"
	qui estadd local cont2 "Y"
	qui estadd local cont3 "Y"	
	qui estadd local fe1 "Y"
	qui estadd local fe2 "Y"	
	lincom cash_postpay - cash_announce
	qui estadd scalar coef1 = r(estimate)
	qui estadd scalar se1 = r(se)			
	qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))	
	

	* Heterogeneity continuous
	cap drop *_hiw
	foreach x of varlist cash_postpay cash_announce{
		gen `x'_hiw = `x'*wealth_ind_avg
	}	

	eststo: reghdfe n_productivity cash_postpay cash_announce cash_postpay_hiw cash_announce_hiw wealth_ind_avg blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
	qui estadd local cont1 "Y"
	qui estadd local cont2 "Y"
	qui estadd local cont3 "Y"	
	qui estadd local fe1 "Y"
	qui estadd local fe2 "N"
	qui estadd local index "Continuous"	
	lincom cash_postpay - cash_announce
	qui estadd scalar coef1 = r(estimate)
	qui estadd scalar se1 = r(se)			
	qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))	
	qui lincom cash_postpay + cash_postpay_hiw
	qui estadd scalar coef2 = r(estimate)
	qui estadd scalar se2 = r(se)			
	qui estadd scalar pval2 = 2*ttail(r(df),abs(r(estimate)/r(se)))	
	
	* Heterogeneity binary
	cap drop *_hiw
	foreach x of varlist cash_postpay cash_announce{
		gen `x'_hiw = `x'*wealth_hi_avg
	}		

	eststo: reghdfe n_productivity cash_postpay cash_announce cash_postpay_hiw cash_announce_hiw wealth_hi_avg blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
	qui estadd local cont1 "Y"
	qui estadd local cont2 "Y"
	qui estadd local cont3 "Y"	
	qui estadd local fe1 "Y"
	qui estadd local fe2 "N"
	qui estadd local index "Binary"
	lincom cash_postpay - cash_announce
	qui estadd scalar coef1 = r(estimate)
	qui estadd scalar se1 = r(se)			
	qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))	
	qui lincom cash_postpay + cash_postpay_hiw
	qui estadd scalar coef2 = r(estimate)
	qui estadd scalar se2 = r(se)			
	qui estadd scalar pval2 = 2*ttail(r(df),abs(r(estimate)/r(se)))	
	
	
label var cash_postpay_hiw "Cash $\times$ Post-pay $\times$ Higher wealth" 
label var cash_announce_hiw "Cash $\times$ Announcement $\times$ Higher wealth" 
	
#delimit ;
local tablerow cash_postpay cash_postpay_hiw cash_announce cash_announce_hiw;

esttab using "$om/$t/Table_3.tex", 
    b(3) se booktabs star(* .1 ** .05 *** .01) collabels(,none) nonotes nomtitles 
    replace label style(tex) gaps keep(`tablerow') order(`tablerow') 
    stats(cont1 cont2 cont3 fe2 fe1 pval1 index coef2 se2 pval2 N, labels("Linear baseline output" "Quadratic baseline output" "Post-double selection lasso controls" "Day FE and hour FE" "Round-wave FE" "P-val: Cash $\times$ Post-pay = Cash $\times$ Announcement" "Wealth index" "Coef: Cash $\times$ Post-pay + Cash $\times$ Post-pay $\times$ Wealth" "SE: Cash $\times$ Post-pay + Cash $\times$ Post-pay $\times$ Wealth" "P-val: Cash $\times$ Post-pay + Cash $\times$ Post-pay $\times$ Wealth" "N: worker-hours") fmt(%50s %50s %50s %50s %50s %9.3fc %50s %9.3fc %9.3fc %9.3fc %9.0fc))    
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
	\begin{tabular}     
	{@{\extracolsep{4pt}}l*{15}{>{\centering\arraybackslash}m{2.5cm}}@{}}      \toprule    
	&\multicolumn{6}{c}{\textbf{Hourly Production}}     \bigstrut       \\ 
	\cline{2-7} \addlinespace 	
	") ;
		
#delimit cr	


